package com.ss.android.article.base.feature.splash;

import android.app.Activity;
import android.app.Application;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bytedance.common.utility.Logger;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.a.ABHelper;
import com.ss.android.account.Spipe;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.app.r;
import com.ss.android.article.base.feature.feed.FeedTab;
import com.ss.android.article.base.feature.shrink.extend.ArticleBaseExtendManager;
import com.ss.android.article.base.feature.video.IMediaViewLayout.CtrlFlag;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.base.feature.video.IVideoController.ISplashAdListener;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.e.VideoControllerSupplierProxy;
import com.ss.android.b.AdManager;
import com.ss.android.b.a.m;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.newmedia.BaseApplication;
import com.ss.android.newmedia.activity.AbsSplashActivity;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.EnumSet;

public abstract class BaseSplashActivity extends AbsSplashActivity implements com.ss.android.article.base.app.r.a {
    int a;
    boolean b;
    private boolean c;
    private int n;
    private IVideoController mVideoController;
    private ISplashAdListener mSplashAdListener;
    private FrameLayout mSplashVideoFrame;
    private ViewGroup mSplashVideoLayout;
    private ImageView mIvAdSplashHasWifiLoaded;
    private ProgressDialog mProgressDialog;

    public BaseSplashActivity() {
        this.c = false;
        this.n = 0;
        this.a = 0;
        this.b = false;
    }

    public static void a(Activity activity) {
        int v0 = 1;
        com.ss.android.l.c.b();
        int v2 = AppData.getInstance().ck > 0 ? 1 : 0;
        if (v2 != 0) {
            ArticleBaseExtendManager.getInstance().loadAppseeStatisticsAdapter();
        }

        if (AppData.getInstance().key_allow_regist_device_manager <= 0) {
            v0 = 0;
        }

        if (v0 != 0) {
            ArticleBaseExtendManager.getInstance().loadRegistDeviceManagerAdapter();
        }
        ArticleBaseExtendManager.getInstance().loadGoogleAdAdapter();
        AppData.getInstance();
        AppData.tryInitCanDelayed(activity);
        new StringBuilder("SplayDelayIn").append(activity.getClass().getSimpleName());
        com.ss.android.l.c.c();
    }

    static void a(BaseSplashActivity arg0) {
        arg0.p();
    }

    static void a(BaseSplashActivity arg0, AdManager.b arg1) {
        arg0.b(arg1);
    }

    static void b(BaseSplashActivity arg0) {
        arg0.p();
    }

    static void b(BaseSplashActivity arg0, AdManager.b arg1) {
        arg0.b(arg1);
    }

    static void c(BaseSplashActivity arg0) {
        arg0.p();
    }

    private void a(String arg12, String arg13, long arg14, JSONObject arg16) {
        MobAdClickCombiner.onAdEvent(this, arg12, arg13, arg14, 0, arg16, 3);
    }

    public final void a() {
        this.m.post(new Runnable() {

            public final void run() {
                BaseSplashActivity.this.a(true);
            }
        });
    }

    public final void a(DialogInterface arg1, boolean arg2) {
        super.a(arg1, arg2);
        if (arg2) {
            com.ss.android.article.base.utils.e.c();
        } else {
            com.ss.android.article.base.utils.e.d();
        }
    }

    protected final void a(AdManager.b arg8, boolean arg9) {
        JSONObject v6;
        if (!this.j) {
            try {
                v6 = new JSONObject();
                if (android.support.design.a.isTextEmpty(arg8.logExtra)) {
//                    goto label_11;
                } else {
                    v6.put("log_extra", arg8.logExtra);
                }
            } catch (Exception v0) {
                v6 = null;
            }

//            label_11:
            String v2 = "splash_ad";
            String v3 = arg9 ? "click" : "banner_click";
            this.a(v2, v3, arg8.id, v6);
            this.a = 1;
            if (!this.a(arg8, v6)) {
                return;
            }

            if (this.mVideoController == null) {
                return;
            }

            this.mVideoController.pauseVideo();
        }
    }

    final void a(boolean arg3) {
        try {
            this.m.removeMessages(12);
            if (this.mProgressDialog != null && (this.mProgressDialog.isShowing())) {
                this.mProgressDialog.dismiss();
            }

            if (arg3) {
                MobClickCombiner.onEvent(((Context) this), "lite_ui_version", "request_success");
            } else {
                MobClickCombiner.onEvent(((Context) this), "lite_ui_version", "request_fail");
            }

            if (Logger.debug()) {
                String v1 = "ObserverManager";
                String v0_1 = arg3 ? "onSuccess " : "onFail BaseSplashActivity";
                Logger.d(v1, v0_1);
            }

            super.d();
            com.ss.android.article.base.app.r.a(null);
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
    }

    public final boolean a(final AdManager.b arg23) {
        boolean v4;
        if (arg23 == null) {
            v4 = false;
            return v4;
        }

        if (arg23.q == 0) {
            return super.a(arg23);
        }

        Logger.d("BaseSplashActivity", "show Video splash ad");
        final m v20 = arg23.r;
        if (v20 == null) {
            return false;
        }

        this.mSplashVideoLayout.setVisibility(View.VISIBLE);
        this.mVideoController = VideoControllerSupplierProxy.getInstance().createVideoControllerDirectly(this, this.mSplashVideoFrame, false, EnumSet.of(CtrlFlag.hideCloseBtn, CtrlFlag.fixedSize));
        JSONObject v21 = new JSONObject();
        try {
            v21.put("log_extra", arg23.logExtra);
        } catch (JSONException v4_1) {
            v4_1.printStackTrace();
        }

        this.mSplashAdListener = new ISplashAdListener() {

            public final void onComplete(long arg3, int arg5) {
                BaseSplashActivity.this.b = true;
                AppUtil.a(v20.c, BaseApplication.getApplication());
                BaseSplashActivity.a(BaseSplashActivity.this);
            }

            public final void onError(long arg2, int arg4) {
                BaseSplashActivity.b(BaseSplashActivity.this);
            }

            public final void onSkip(long arg3, int arg5) {
                BaseSplashActivity.this.a = 2;
                BaseSplashActivity.a(BaseSplashActivity.this, arg23);
            }

            public final void onTimeOut() {
                BaseSplashActivity.c(BaseSplashActivity.this);
            }

            public final void onVideoClick(long arg4, int arg6) {
                AppUtil.a(v20.d, BaseApplication.getApplication());
                BaseSplashActivity.this.a(arg23, true);
            }
        };
        this.mVideoController.setSplashAdListener(this.mSplashAdListener);
        v4 = false;
        if (arg23.q == 3) {
            this.mIvAdSplashHasWifiLoaded.setVisibility(View.VISIBLE);
            ViewGroup.LayoutParams layoutParams = this.mSplashVideoLayout.getLayoutParams();
            layoutParams.height = -1;
            layoutParams.width = -1;
            ((RelativeLayout.LayoutParams) layoutParams).addRule(2, R.id.banner_view);
            this.mSplashVideoLayout.setLayoutParams(layoutParams);
            DisplayMetrics v12 = this.getResources().getDisplayMetrics();
            int v17 = v12.heightPixels - AdManager.getInstance(((Context) this)).e() - (((int) this.getResources().getDimension(R.dimen.splash_banner_margin_bottom)));
            Logger.d("BaseSplashActivity", "splashHeight = " + v17);
            int picHeight = arg23.a.mHeight;
            int videoHeight = arg23.r.videoHeight;
            Logger.d("BaseSplashActivity", "videoHeight = " + videoHeight);
            Logger.d("BaseSplashActivity", "picHeight = " + picHeight);
            if (picHeight != 0 && videoHeight != 0) {
                v4 = AdManager.getInstance((Context) this).tryShowImageSplash(this, arg23, this.e, this.d, null, null);
                videoHeight = (int) ((float) videoHeight * ((float) v17 / (float) picHeight));
                v4 = !this.mVideoController.playSplashUrl(v20.f, v20.e, null, null, arg23.id, v12.widthPixels, videoHeight, v20.a, null, arg23.logExtra, (v17 - videoHeight) / 2, false, false) || !v4 ? false : true;
                View v6 = this.f;
                int v5 = arg23.n == 1 ? View.VISIBLE : View.GONE;
                v6.setVisibility(v5);
                this.f.setOnClickListener(new View.OnClickListener() {

                    public final void onClick(View arg3) {
                        BaseSplashActivity.this.a = 2;
                        BaseSplashActivity.b(BaseSplashActivity.this, arg23);
                    }
                });
                this.g.setOnClickListener(new View.OnClickListener() {


                    public final void onClick(View arg4) {
                        AppUtil.a(v20.d, BaseApplication.getApplication());
                        BaseSplashActivity.this.a(arg23, false);
                    }
                });
                if (!v4) {
//                    goto label_192;
                } else {
                    this.a("splash_ad", "banner_show", arg23.id, v21);
//                    goto label_192;
                }
            } else {
                return false;
            }
        } else {
            if (arg23.q != 2) {
//                goto label_192;
            } else {
                boolean v19 = arg23.n == 1 ? true : false;
                v4 = this.mVideoController.playSplashUrl(v20.f, v20.e, null, null, arg23.id, this.mSplashVideoLayout.getWidth(), this.mSplashVideoLayout.getHeight(), v20.a, null, arg23.logExtra, 0, true, v19);
                if (!v4) {
//                goto label_192;
                } else {
                    com.ss.android.b.bb.a().a(System.currentTimeMillis());
                }
            }
        }

        label_192:
        if (v4) {
            this.m.sendEmptyMessageDelayed(102, arg23.c());
        }

        Logger.d("BaseSplashActivity", "is ok? " + v4);
        this.i();
        com.bytedance.ttstat.a.c(((Activity) this));
        return v4;
    }

    public final void b() {
        if (this.isViewValid()) {
            AppData v3 = AppData.getInstance();
            int v2 = v3.launchShowCount > 0 ? 1 : 0;
            int v0 = v2 != 0 ? v3.launchShowCount - 1 : 1;
            super.b();
            if (v2 == 0 && v3.showIntroductionCount <= 1) {
                ++v3.showIntroductionCount;
                v3.cL = true;
                return;
            }

            if (v2 == 0) {
                return;
            }

            if (v3.showLaunchLoginCount > v0) {
                return;
            }

            ++v3.showLaunchLoginCount;
            v3.cL = true;
        }
    }

    public abstract Intent c();

    public final void d() {
        int v0 = 0;
        if (!"launch_new".equals(ABHelper.a(AppData.getInstance().getAppContext()).ttLiteReduceLaunchTime)) {
            r v2 = com.ss.android.article.base.app.r.a();
            if (v2.b.contains("lite_ui_style_config_first_install")) {
                v0 = 1;
            } else {
                v2.b.edit().putBoolean("lite_ui_style_config_first_install", false).apply();
            }

            if (v0 != 0) {
                label_16:
                Logger.d("BaseSplashActivity", "Already got lite ui style, go to main activity.");
                super.d();
                return;
            }

            this.mProgressDialog = com.ss.android.j.b.createProgressDialog(((Context) this));
            this.mProgressDialog.setMessage(this.getResources().getString(com.ss.android.article.browser.R.string.l7));
            this.mProgressDialog.show();
            this.mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

                public final void onCancel(DialogInterface arg4) {
                    MobClickCombiner.onEvent(BaseSplashActivity.this, "lite_ui_version", "request_cancel");
                    BaseSplashActivity.this.a(false);
                }
            });
            this.mProgressDialog.setCanceledOnTouchOutside(true);
            if (Logger.debug()) {
                Logger.d("BaseSplashActivity", "setFirstConfigUpdateCallback");
            }

            com.ss.android.article.base.app.r.a(((com.ss.android.article.base.app.r.a) this));
            this.m.sendEmptyMessageDelayed(12, 5000);
        } else {
            label_16:
            Logger.d("BaseSplashActivity", "Already got lite ui style, go to main activity.");
            super.d();
        }
    }

    public final Intent e() {
        Intent v0 = this.c();
        if (v0 != null) {
            if (this.c) {
                v0.putExtra("view_update", true);
            }

            if (this.n <= 0) {
                return v0;
            }

            v0.putExtra("sso_auth_ext_value", this.n);
        }

        return v0;
    }

    public boolean f() {
        boolean v0 = false;
        Intent v1 = this.getIntent();
        if (v1 != null && (v1.getBooleanExtra("quick_launch", false))) {
            v0 = true;
        }

        return v0;
    }

    public final void g() {
        super.g();
    }

    public boolean getScreenSwitch() {
        return super.getScreenSwitch();
    }

    public final void h() {
        super.h();
        Intent v0 = this.getIntent();
        if (v0 != null && (v0.getBooleanExtra("view_update", false))) {
            this.c = true;
        }

        AppData.getInstance().b(((Context) this));
    }

    public void handleMsg(Message message) {
        if (this.isViewValid()) {
            switch (message.what) {
                case 12: {
                    this.a(false);
                    return;
                }
                default: {
                    super.handleMsg(message);
                    return;
                }
            }
        }
    }

    public final void i() {
        com.ss.android.article.base.utils.e.a();
        com.ss.android.article.base.utils.e.a(10003);
        super.i();
        com.bytedance.ttstat.a.a();
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        int v6 = 104;
        int v5 = 103;
        int v2 = 102;
        int v4 = 108;
        if (requestCode == 109) {
            this.d();
        } else {
            if (requestCode != v2 && requestCode != v5 && requestCode != v6 && requestCode != 105 && requestCode != 106 && requestCode != 107 && requestCode != v4 && requestCode != 110 && requestCode != 111) {
                super.onActivityResult(requestCode, resultCode, intent);
                return;
            }

            if (requestCode != 107) {
                Spipe v0 = Spipe.inst();
                if (v0 != null) {
                    if (requestCode == v2 && (v0.d("sina_weibo"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "recommend_login_sina_success");
                    }

                    if (requestCode == v5 && (v0.d("qq_weibo"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "recommend_login_qq_success");
                    }

                    if (requestCode == v6 && (v0.d("qzone_sns"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "recommend_login_qzone_success");
                    }

                    if (requestCode == 105 && (v0.d("renren_sns"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "recommend_login_renren_success");
                    }

                    if (requestCode == 106 && (v0.d("kaixin_sns"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "recommend_login_kaixin_success");
                    }

                    if (requestCode == v4 && (v0.d("weixin"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "login_weixin_success");
                    }

                    if (requestCode == v4 && (v0.d("weixin"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "login_weixin_success");
                    }

                    if (requestCode == 110 && (v0.d("flyme"))) {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "login_flyme_success");
                    }

                    if (requestCode != 111) {
//                        goto label_94;
                    } else if (!v0.d("huawei")) {
//                        goto label_94;
                    } else {
                        MobClickCombiner.onEvent(((Context) this), "new_tab", "login_huawei_success");
                    }
                }

//                label_94:
                int v0_1 = resultCode != -1 || intent == null ? 0 : intent.getIntExtra("auth_ext_value", 0);
                if (v0_1 <= 0) {
//                    goto label_101;
                } else {
                    this.n = v0_1;
                }
            }

            label_101:
            this.h = false;
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        com.bytedance.ttstat.a.b(((Activity) this));
        com.ss.android.article.base.utils.e.a(10002);
        com.ss.android.article.base.utils.e.a(10004);
        com.ss.android.l.c.c();
        super.onCreate(savedInstanceState);
        this.getApplication().registerActivityLifecycleCallbacks(new a$a());
        this.mSplashVideoFrame = (FrameLayout) this.findViewById(com.ss.android.article.browser.R.id.splash_video_frame);
        this.mSplashVideoLayout = (ViewGroup) this.findViewById(com.ss.android.article.browser.R.id.splash_video_layout);
        ComponentsManifest.findComponent(com.ss.android.account.v2.bb.class);
        this.mIvAdSplashHasWifiLoaded = (ImageView) this.findViewById(com.ss.android.article.browser.R.id.ad_splash_has_wifi_loaded);
        com.ss.android.l.c.c();
    }

    public void onDestroy() {
        super.onDestroy();
        com.ss.android.article.base.utils.e.c();
    }

    public void onPause() {
        com.ss.android.article.base.utils.e.c();
        super.onPause();
    }

    public void onPostCreate(Bundle arg2) {
        super.onPostCreate(arg2);
        com.ss.android.article.base.utils.e.b(10004);
    }

    public void onResume() {
        com.ss.android.article.base.utils.e.d();
        super.onResume();
        com.ss.android.article.base.utils.e.b(10004);
        com.bytedance.ttstat.a.e(((Activity) this));
    }

    public void onStop() {
        if (this.mVideoController != null && (this.mVideoController.isVideoVisible())) {
            Logger.d("BaseSplashActivity", "onStop release media");
            if (!this.isFinishing()) {
                this.a = 7;
            }
            mVideoController.releaseMediaFromSplash(!this.b, this.a);
        }

        super.onStop();
    }

    final class a$a implements Application.ActivityLifecycleCallbacks {

        private a$a() {

        }

        public final void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            activity.getApplication().unregisterActivityLifecycleCallbacks(this);
            if ((activity instanceof FeedTab)) {
                ((FeedTab) activity).addDelayInitCallback(new FeedTab.DelayInitCallback(activity));
            } else {
                BaseSplashActivity.a(activity);
            }
        }

        public final void onActivityDestroyed(Activity activity) {
        }

        public final void onActivityPaused(Activity activity) {
        }

        public final void onActivityResumed(Activity activity) {
        }

        public final void onActivitySaveInstanceState(Activity activity, Bundle outState) {
        }

        public final void onActivityStarted(Activity activity) {
        }

        public final void onActivityStopped(Activity activity) {
        }
    }
}

